#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include "rngs.h"
#include<time.h>

#define CONDITION_COUNT 100
#define TEST_COUNT 10000 //Arbitrary

int main(int argc, char **argv)
{
	int i, j, temp_card, temp_coin, return_val;
	int current_player;
	int flag = 0;
	int player_count;
	int seedy;

	struct gameState state;
	int k[10] = {great_hall, outpost, steward, smithy, adventurer, council_room, gardens, sea_hag, salvager, baron};
	
	srand(time(NULL));
	
	//case adventurer
	int test_card = adventurer;
	int choice1 = -1;
	int choice2 = -1;
	int choice3 = -1;
	int handPos = -1;
	int *myBonus = 0;
	
	
	
	for(i = 0; i < CONDITION_COUNT; i++)
	{
		//Initialize random game settings
		player_count = rand()%3 + 2;
		seedy = rand();
		
		for(j = 0; j < TEST_COUNT; j++)
		{
			initializeGame(player_count, k, seedy, &state);
			state.whoseTurn = rand() % (player_count);
			current_player = state.whoseTurn;

		
			//printf("%d, %d, %d\n", i, player_count, seedy);
			
			state.coins += rand()%15;
			temp_coin = state.coins;
			temp_card = state.handCount[current_player];
			
			return_val = cardEffect(test_card, choice1, choice2, choice3, &state, handPos, myBonus);
			
			if(return_val)
			{
				printf("Detected improper return value. Seed:%d\nPlayers:%d\nIteration:%d\nSub-Iteration:%d\n\n", seedy, player_count, i, j);
				flag++;
			}
			else if(temp_card > state.handCount[current_player]) //draw two, discard one
			{
				printf("Detected improper hand count. Seed:%d\nPlayers:%d\nIteration:%d\nSub-Iteration:%d\n\n", seedy, player_count, i, j);
				flag++;
			}
			else if(temp_coin > state.coins)
			{
				printf("Detected improper coin count. Seed:%d\nPlayers:%d\nIteration:%d\nSub-Iteration:%d\n", seedy, player_count, i, j);
				flag++;
			}
		}
			
		
	}

	
	printf("randomtestcard.c: adventure returned %d error(s).\n", flag);
	
	return 0;

}



// int great_hall_effect(int currentPlayer, int handPos, struct gameState *state)
// {
  // //+1 Card
  // drawCard(currentPlayer, state);
		
  // //+1 Actions
  // state->numActions++;
		
  // //discard card from hand
  // discardCard(handPos, currentPlayer, state, 0);
  // return 0;


// }